package DynamicProgramming;

public class _712_MinimumASCIIDeleteSumforTwoStrings {
    //this method can handle the situation that the string is unorder, but not in order.
    public int minimumDeleteSum(String s1, String s2) {
        int[] count = new int[26];
        int sum = 0;
        for (int i = 0; i < s1.length(); i++) {
            count[s1.charAt(i) - 'a']++;
        }
        for (int i = 0; i < s2.length(); i++) {
            count[s2.charAt(i) - 'a']--;
        }
        for (int i = 0; i < 26; i++) {
            if (count[i] != 0) {
                sum += (97 + i) * Math.abs(count[i]);
            }
        }
        return sum;
    }
}
